package com.dididoctor.doctor.Activity.Main.Inquiry.NewInquiry.AddSelectAnswer;

import android.annotation.SuppressLint;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.dididoctor.doctor.MV.BaseFragment;
import com.dididoctor.doctor.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @version 2.0
 * @类描述：
 * @项目名称：ddgh
 * @类名称： AddSelectAnswerFragment
 * @包名称： com.dididoctor.doctor.Activity.Main.Inquiry.NewInquiry
 * @创建人： zhanjunjie
 * @创建时间：2016/4/21 20:23
 * @修改人：
 * @修改时间：2016/4/21 20:23
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
@SuppressLint("ValidFragment")
public class AddSelectAnswerFragment extends BaseFragment {
    private EditText mEtContent;
    private ListView listView;
    private TextView MTvAddAnswer;
    private Context context;
    private AddSelectAnswerAdapter adapter;
    private List<AnswerBean> answerBeans = new ArrayList<>();

    public AddSelectAnswerFragment(Context context) {
        this.context = context;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_add_select_answer, null);
        View footView = inflater.inflate(R.layout.list_answer_foot, null);
        this.initview(rootView, footView);
        return rootView;
    }

    private void initview(View rootView, View footView) {
        mEtContent = (EditText) rootView.findViewById(R.id.et_content);
        listView = (ListView) rootView.findViewById(R.id.listview);
        listView.addFooterView(footView);
        for (int i = 0; i < 3; i++) {
            AnswerBean answerBean = new AnswerBean();
            answerBeans.add(answerBean);
        }
        adapter = new AddSelectAnswerAdapter(context, answerBeans);
        listView.setAdapter(adapter);
        //尾部处理
        MTvAddAnswer = (TextView) footView.findViewById(R.id.tv_addanswer);
        MTvAddAnswer.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AnswerBean answerBean = new AnswerBean();
                answerBeans.add(answerBean);
                adapter.notifyDataSetChanged();
            }
        });

    }

    public String answercontent() {
        String content = mEtContent.getText().toString();
        return content;
    }

    public List<AnswerBean> answerlist() {
        return answerBeans;
    }
}
